package com.company;

import javax.net.ssl.SSLContext;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入licensePlate:");
        String licensePlate = sc.nextLine();
        System.out.println("请输入字符串数组的元素个数");
        int n = sc.nextInt();
        String[] words = new String[n];
        System.out.println("请输入字符串数组中的各个元素");
        for(int i = 0; i < n; i++)
        {
            words[i] = sc.next();
        }
        System.out.println("字符串数组中的最短补全词为" + shortestCompletingWord(licensePlate,words));


    }
    public static String shortestCompletingWord(String licensePlate, String[] words) {
        int[] table = new int[26];
        for (int i = 0; i < licensePlate.length(); i++)
        {
            char ch = licensePlate.charAt(i);
            if (Character.isLetter(ch))
            {
                table[Character.toLowerCase(ch) - 'a']++;
            }
        }
        int index = -1;
        for(int i = 0;  i < words.length; i++)
        {
            int[] wordTable = new int[26];
            for(int j = 0; j < words[i].length(); j++)
            {
                int ch2 = words[i].charAt(j);
                if(Character.isLetter(ch2))
                {
                    wordTable[Character.toLowerCase(ch2) - 'a']++;
                }
            }
            boolean flag = true;
            for(int k = 0; k < 26; k++)
            {
                if(wordTable[k] < table[k])
                {
                    flag = false;
                    break;
                }
            }
            if(flag && (index < 0 || words[index].length() > words[i].length()))
            {
                index = i;
            }
        }
        return words[index];
    }
}
